#!/bin/bash
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

UI_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
ROOT_DIR=$(dirname "$UI_DIR")

if [ -z "$1" ]; then
  echo "ERROR: no output directory specified."
  echo "Usage: $0 out/mac_debug"
  exit 127
fi
OUT_DIR="$1"

echo 'Initial build:'
$ROOT_DIR/tools/ninja -C $OUT_DIR ui

UI_OUT_DIR="$OUT_DIR/ui"
if [ ! -d $UI_OUT_DIR ]; then
  echo "ERROR: cannot find the UI output directory (\"$UI_OUT_DIR\")."
  echo "Did you run ninja ui?"
  exit 127
fi

$ROOT_DIR/tools/dev_server \
  -p 10000 \
  -i $ROOT_DIR/.git \
  -i $ROOT_DIR/src/traced \
  -i $ROOT_DIR/buildtools \
  -i $ROOT_DIR/out \
  -i $ROOT_DIR/infra \
  -i $ROOT_DIR/ui/node_modules \
  -s $UI_OUT_DIR \
  "$ROOT_DIR/tools/ninja -C $OUT_DIR ui"


